package com.gopay.cron.service.cloud.gen.bean;

import com.gopay.cron.web.vo.CloudAccountStatementVO;

/**
 * Created by Johnson on 2017/3/1.
 */
public class RecvFileInfo {

    public static final String fileName = "01";
    public static final String fileFtpName = "收款类";

    public static final String txtFirstLine = "商户订单号\t国付宝账户号\t收款类型\t交易请求时间\t清算时间\t交易金额\t手续费\t入账金额\t支付渠道";
    public static final String csvFirstLine = "\"商户订单号\",\"国付宝账户号\",\"收款类型\",\"交易请求时间\",\"清算时间\",\"交易金额\",\"手续费\",\"入账金额\",\"支付渠道\"";

    private static final String csvFtpFirstLine = "\"商户账户\",\"收款总笔数\",\"收款总金额\",\"收款总手续费\"";
    private static final String csvFtpSecondLine = "\"国付宝交易号\",\"商户订单号\",\"交易类型\",\"交易时间\",\"完成时间\",\"交易金额\",\"手续费\",\"支付渠道\"";

    private StringBuilder txtLineContent = new StringBuilder();
    private StringBuilder csvLineContent = new StringBuilder();
    private StringBuilder csvFtpFirstLineContent = new StringBuilder();
    private StringBuilder csvFtpSecondLineContent = new StringBuilder();

    public void addRecvFileLine(CloudAccountStatementVO vo) {
        addTxtFileLine(vo);
        addCsvFileLine(vo);
    }


    public void addTxtFileLine(CloudAccountStatementVO vo) {
        txtLineContent.append(vo.getMerOrderId()).append("\t")
                .append(vo.getGopayAcct()).append("\t")
                .append(vo.getGopayIntTxnCd()).append("\t")
                .append(vo.getReqTime()).append("\t")
                .append(vo.getTranFinishTime()).append("\t")
                .append(vo.getMerTxnAmt()).append("\t")
                .append(vo.getOrderFeeAmt()).append("\t")
                .append(vo.getRealAmt()).append("\t")
                .append(vo.getPayChannel())
                .append("\r\n");
    }

    public void addCsvFileLine(CloudAccountStatementVO vo) {
        csvLineContent.append("\"").append(vo.getMerOrderId()).append("\",")
                .append("\"").append(vo.getGopayAcct()).append("\",")
                .append("\"").append(vo.getGopayIntTxnCd()).append("\",")
                .append("\"").append(vo.getReqTime()).append("\",")
                .append("\"").append(vo.getTranFinishTime()).append("\",")
                .append("\"").append(vo.getMerTxnAmt()).append("\",")
                .append("\"").append(vo.getOrderFeeAmt()).append("\",")
                .append("\"").append(vo.getRealAmt()).append("\",")
                .append("\"").append(vo.getPayChannel()).append("\"")
                .append("\r\n");
    }

    public String getTxtContent() {
        StringBuilder sb = new StringBuilder(RecvFileInfo.txtFirstLine);
        sb.append("\r\n").append(txtLineContent.toString());
        return sb.toString();
    }

    public String getCsvContent() {
        StringBuilder sb = new StringBuilder(RecvFileInfo.csvFirstLine);
        sb.append("\r\n").append(csvLineContent.toString());
        return sb.toString();
    }

    public String getFtpCsvContent() {
        StringBuilder sb = new StringBuilder(RecvFileInfo.csvFtpFirstLine);
        sb.append("\r\n").append(csvFtpFirstLineContent.toString());
        sb.append(RecvFileInfo.csvFtpSecondLine);
        sb.append("\r\n").append(csvFtpSecondLineContent.toString());
        return sb.toString();
    }

    public void addFtpFirstRecvFileLine(CloudAccountStatementVO vo) {
        addFtpFirstCsvFileLine(vo);
    }

    private void addFtpFirstCsvFileLine(CloudAccountStatementVO vo) {
        csvFtpFirstLineContent.append("\"").append(vo.getGopayAcct()).append("\",")
                .append("\"").append(vo.getTotalCount()).append("\",")
                .append("\"").append(vo.getTotalTxnAmt()).append("\",")
                .append("\"").append(vo.getTotalFeeAmt()).append("\"")
                .append("\r\n");
    }

    public void addFtpSecondRecvFileLine(CloudAccountStatementVO vo) {
        addFtpSecondCsvFileLine(vo);
    }

    private void addFtpSecondCsvFileLine(CloudAccountStatementVO vo) {
        csvFtpSecondLineContent.append("\"").append(vo.getGopayOrderId()).append("\",")
                .append("\"").append(vo.getMerOrderId()).append("\",")
                .append("\"").append(vo.getGopayIntTxnCd()).append("\",")
                .append("\"").append(vo.getReqTime()).append("\",")
                .append("\"").append(vo.getTranFinishTime()).append("\",")
                .append("\"").append(vo.getMerTxnAmt()).append("\",")
                .append("\"").append(vo.getOrderFeeAmt()).append("\",")
                .append("\"").append(vo.getPayChannel()).append("\"")
                .append("\r\n");
    }

}
